package com.sky.controller.user;


import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.Orders;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "购物车接口")
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 新增购物车数据
     *
     * @param shoppingCartDTO
     * @return
     */
    @ApiOperation("新增购物车")
    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.add(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 查看购物车数据
     *
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查看购物车数据")
    public Result<List<ShoppingCart>> list() {
        List<ShoppingCart> listShoppingCart = shoppingCartService.list();
        return Result.success(listShoppingCart);
    }

    /**
     * 清空购物车
     *
     * @return
     */
    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
    public Result clean() {
        shoppingCartService.clean();
        return Result.success();
    }

    /**
     * 删除单个数据
     *
     * @param shoppingCartDTO
     * @return
     */
    @ApiOperation("删除单个")
    @PostMapping("/sub")
    public Result deleteOne(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.deleteOne(shoppingCartDTO);
        return Result.success();
    }


}
